package com.dudu.timer;

import java.util.List;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.dudu.dao.PushNoticeInfoDao;
import com.dudu.model.PushNoticeInfo;
import com.dudu.utils.ThreadPoolUtils;

import core.CoreDao;
import core.CoreDaoInvoke;
/**
 * 开始定时
 * 向调用方推送IMS返回的SESSION_id
 * @author gaoxs
 *
 */
public class SendVoiceSessionInfoJob implements Job {

	private static final Logger log =  core.util.Logger.getLogger(SendVoiceSessionInfoJob.class.getSimpleName());
	
	private CoreDao dao = CoreDaoInvoke.getInstance();
	private PushNoticeInfoDao mPushNoticeInfoDao = new PushNoticeInfoDao();
	
	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {

		//log.info("开始定时语音SESSION推送任务");
		List<PushNoticeInfo>  mSendNoticeList = mPushNoticeInfoDao.queryAllNumber(dao);
		
		if(mSendNoticeList != null){
		
			//更新语音通知的线程状态
			long threadid = System.currentTimeMillis();
			for(int i=0;i<mSendNoticeList.size();i++){
				PushNoticeInfo notice = mSendNoticeList.get(i);
				notice.setRun_thread(threadid+"");
				mPushNoticeInfoDao.updateRunThread(dao, notice);
				
				if(notice.getSend_count()<3){
					SendVoiceInfoThread voiceinfo = new SendVoiceInfoThread(dao,notice,mPushNoticeInfoDao);
					ThreadPoolUtils.getThreadPoolUtils().getExecutorService().execute(voiceinfo);
				}
				
			}
			
		}
	}
}
